#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[21],b[21],ncnt,vis[21];
unsigned int tmp=0;
bool chk(int num,int dep){
	tmp=0;
	// cerr<<dep<<" "<<num<<"\n";
	// for(int i=1;i<dep;i++)cerr<<b[i]<<" ";
	for(int i=dep-1;i>0;i--){
		if(tmp>>(max(num,b[i]))&&(tmp^((tmp>>(min(num,b[i])-1))<<(min(num,b[i])-1))))return 0;
		tmp|=1<<(b[i]-1);
		// cerr<<bitset<6>(tmp)<<" "<<(tmp<<32)<<" "<<b[i-1]<<" "<<(tmp>>(max(num,b[i-1])))<<" "<<(tmp<<(33-min(num,b[i-1])))<<"\n";
	}
	return 1;
}
void dfs(int dep){
	if(dep>n){
		ans=min(ncnt,ans);
		return;
	}
	if(ncnt>=ans)return;
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		if(!chk(i,dep))continue;
		vis[i]=1;
		b[dep]=i;
		if(i==a[dep]){
			dfs(dep+1);
		}else{
			ncnt++;
			dfs(dep+1);
			ncnt--;
		}
		vis[i]=0;
	}
	return;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	ans=n;
	dfs(1);
	cout<<ans;
	return 0;
}